import { _decorator, BlockInputEvents, Component, Node, Size, UITransform, view } from 'cc';
import { UIBase } from './UIBase';
const { ccclass, property } = _decorator;

@ccclass('UIWindow')
export class UIWindow extends Component {
    protected _blockNode:Node=null;
    private _uiTransform:UITransform = null;
    get uiTrasform(){
        if(!this._uiTransform){
            this._uiTransform = this.node.getComponent(UITransform);
        }
        return this._uiTransform;
    }
   
    private _blockSize:Size = null;
    start(...rest: any[]): void {
        this.CreateBlock();
        //再调用uibase的init
    }
    @property({displayName:'是否全屏拦截',tooltip:'勾起来全屏，不勾以当前UI节点大小进行拦截'})
    isBlockFullScreen:boolean = false;
    CreateBlock(){
        this._blockNode=new Node();
        this._blockSize=this.uiTrasform.contentSize;
        this._blockNode.parent=this.node;
        this._blockNode.setSiblingIndex(-100);
        this._blockNode.addComponent(BlockInputEvents);
        let blockUITransform=this._blockNode.addComponent(UITransform)
        blockUITransform.contentSize=this._blockSize;
        if(this.isBlockFullScreen){
            blockUITransform.contentSize = view.getDesignResolutionSize();
            //拦截节点的偏移，确保他一定要居中。
            let x = this.node.position.x;
            let y = this.node.position.y;
            this._blockNode.setPosition(-x,-y);
        }

    }
}


